﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Nirvana
{
    [AddComponentMenu("Nirvana/UI/Bind/Event Bind Touch")]
    public class UIEventBindTouch : UIEventBind, IPointerDownHandler, IPointerUpHandler
    {
        [EventName]
        [SerializeField]
        private string downEventName;

        [EventName]
        [SerializeField]
        private string upEventName;
        private SignalEvent onPointerDownEvent, onPointerUpEvent;

        protected override void RefreshBind()
        {
            this.onPointerDownEvent = base.GetSignalEvent(this.downEventName);
            this.onPointerUpEvent = base.GetSignalEvent(this.upEventName);
        }

        public void OnPointerDown(PointerEventData eventData)
        {
            SignalEvent _event = this.FindSignalDownEvent();
            if (_event != null)
            {
                _event.Excute();
            }
        }

         public void OnPointerUp(PointerEventData eventData)
        {
            SignalEvent _event = this.FindSignalUpEvent();
            if (_event != null)
            {
                _event.Excute();
            }
        }

        private SignalEvent FindSignalDownEvent()
        {
            if (this.onPointerDownEvent == null)
            {
                this.onPointerDownEvent = base.GetSignalEvent(this.downEventName);
            }
            return this.onPointerDownEvent;
        }
        private SignalEvent FindSignalUpEvent()
        {
            if (this.onPointerUpEvent == null)
            {
                this.onPointerUpEvent = base.GetSignalEvent(this.upEventName);
            }
            return this.onPointerUpEvent;
        }

    }
}

